package com.sali.config;

import com.sali.constants.CommonConstant;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author: sali
 * @date: 2025/2/22 下午1:41.
 * @version: 1.0
 */
@Configuration
@ConfigurationProperties(prefix = "netty-config")
@Data
public class NettyConfig {

    private int port;

    // 负责接收请求
    private int bossGroup;

    // 负责接收客户端读写请求
    private int workerGroup;

    // socket保存队列
    private int socketQueue;

    public int getBossGroup() {
        if (bossGroup < CommonConstant.Netty.BOSS_GROUP_MIN || bossGroup > CommonConstant.Netty.BOSS_GROUP_MAX) {
            bossGroup = 1;
        }
        return bossGroup;
    }

    public int getWorkerGroup() {
        if (workerGroup < CommonConstant.Netty.WORKER_GROUP_MIN || workerGroup > CommonConstant.Netty.WORKER_GROUP_MAX) {
            workerGroup = 4;
        }
        return workerGroup;
    }

    public int getSocketQueue() {
        return socketQueue;
    }
}
